package info.motteke.mixivoice4j.http;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import net.arnx.jsonic.JSON;
import org.apache.http.entity.ContentProducer;

public class JsonContentProducer implements ContentProducer {

    private Object json;

    public JsonContentProducer(Object json) {
        this.json = json;
    }

    @Override
    public void writeTo(OutputStream os) throws IOException {
        Writer w = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
        w.write(JSON.encode(json));
        w.flush();
    }

}
